<?php
 
	if(!isset($_SESSION['realpage']) || $_SESSION['realpage'] == false)
	{
		require './../Pages/hack.php';
		die('');
	}

		
	function startsWith($haystack, $needle)
	{
	    $length = strlen($needle);
	    return (substr($haystack, 0, $length) === $needle);
	}
	
	
	 
	//require_once "class.InfoSingleton.php";	
	$myFile = "../config/UrbanDynamics.properties";
	$fh = fopen($myFile, 'r');
	
	while(!feof($fh))
	{
		$theData = fgets($fh);
		$theData = substr_replace($theData ,"",-1); //str_replace(array("\r\n","\n"),"", $theData);
		$theData = decrypt($theData,$ultKey);
		$prop = explode('=', $theData);
		if (!startsWith($prop[0],"#"))
		{
			switch ($prop[0])
			{	
				case "DBURL":
					$dburl=str_replace(array("\r\n","\n"),"", $prop[1]);
					break;
				case "DBPASS":
					$dbpass=str_replace(array("\r\n","\n"),"", $prop[1]);
					break;
				case "DBUSER":
					$dbhandle=str_replace(array("\r\n","\n"),"", $prop[1]);
					break;
				case "DBPORT":
					$dbport=str_replace(array("\r\n","\n"),"", $prop[1]);
					break;
				case "DBSCHEME":
					$dbname=str_replace(array("\r\n","\n"),"", $prop[1]);
					break;
				default:break;
			}
		}
	}
	fclose($fh);
	$filename = "../config/dbscheme.sql";
	$mysql_host=$dburl.":".$dbport;
	
	// Connect to MySQL server
	$dbcon = mysql_connect($mysql_host, $dbhandle, $dbpass) or ($error=('Error connecting to MySQL server: ' . mysql_error()));
	
	// Select database
	
	
	// Temporary variable, used to store current query
	$templine = '';
	require './../config/dbscheme.php';// Loop through each line
	
	
	if (!isset($error) || $error == "")
	{
		$error = "";
		$argval= " creating db<br><br>creating db<br><br>creating db<br><br>";
		for($i=0;$i<sizeof($dbscheme);$i++)
		{
			$templine = $dbscheme[$i];
			$templine = str_replace("webdb", $dbname, $templine);
	        // Perform the query
	        mysql_query($templine,$dbcon) or ($error.=("\nError performing query \'<strong>" . $templine . '\': ' . mysql_error() . '<br /><br />'));
	        if(strlen($error) > 1)
	        {
	        $error = '';
	        }
		}	
		
		if('' == $error)
		{
			$error = null;
		}
	}
	
	if (!isset($error) || $error == "")
	{
		$argval= " selectintg db<br><br>selectintg db<br><br>selectintg db<br><br>selectintg db<br><br>";
		$sqlSelectDB= "use $dbname ;";
		mysql_query($sqlSelectDB,$dbcon);
		//mysql_select_db($dbname) or ($error=('Error selecting MySQL database: ' . mysql_error()));
	}
	 
	$error = "";
	//$i=0
	for($i=0;$i<sizeof($dbdata);$i++)
	{
		$templine = $dbdata[$i];
		$templine = str_replace("webdb", $dbname, $templine);
	        // Perform the query
	        mysql_query($templine,$dbcon) or ($error.=("\nError performing query \'<strong>" . $templine . '\': ' . mysql_error() . '<br /><br />'));
	        if(strlen($error) > 1)
	        {
	        $error = '';
	        }
	}
?>

